package com.insurance.controller;

import com.insurance.domain.ResponseResult;
import com.insurance.domain.entity.Customer;
import com.insurance.domain.entity.User;
import com.insurance.domain.enums.AppHttpCodeEnum;
import com.insurance.exception.SystemException;
import com.insurance.service.AppLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author qcjstudy
 * @create 2023-04-28 21:03
 */
@RestController
@RequestMapping("/user")
public class AppLoginController {

    @Resource
    private AppLoginService appLoginService;

    @PostMapping("/login")
    public ResponseResult login(@RequestBody User user){
        if(!StringUtils.hasText(user.getUsername())){
            //提示 必须要传用户名
            //使用自己封装的异常处理类
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return appLoginService.login(user);
    }

    @PostMapping("/logout")
    public ResponseResult logout(){
        return appLoginService.logout();
    }
}
